import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
import systemRouter from './modules/System'
import productRouter from './modules/Product'
import analysisRouter from './modules/Analysis'
import memberRouter from './modules/Member'

/**
 * 动态路由
 */
export const asyncRoutes = [{
  path: '/login',
  name: 'login',
  component: () => import('@/views/login'),
  hidden: true
}, {
  path: '/404',
  name: '404',
  component: () => import('@/views/404'),
  hidden: true
}, {
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/dashboard'),
    meta: { title: '主页', icon: 'home' }
  }]
},
productRouter,
memberRouter,
analysisRouter,
systemRouter,
{
  path: 'external-link',
  component: Layout,
  children: [
    {
      path: 'https://www.hnsrmyy.net/',
      meta: { title: '官方网站', icon: 'link' }
    }
  ]
}, {
  path: '*',
  redirect: '/404',
  hidden: true
}]

const createRouter = () => new Router({
  // mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: asyncRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
